package ESP.Control.C;

import java.sql.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import ESP.Dao.BaseDao;
import ESP.Util.IDFactory;
import ESP.VO.Plan;

import com.alibaba.fastjson.JSONArray;

public class c02 {
	@Resource
	public BaseDao baseDao;
	/**
	 * 返回信息
	 */
	private JSONArray rows;
	private Map<String , String> message = new HashMap<String, String>();
	/**
	 * 用户信息
	 */
	private String user_id;
	private String user_role_id;
	/**
	 * 根据id查询表体
	 */
	private String stu_id;
	/**
	 * ESP_PLAN
	 */
	private String plan_id;//
	private String plan_stu_id;//学号
	private String plan_week;//计划周次
	private String plan_expect;//计划完成内容
	private String plan_done;//实际完成内容
	private Date plan_cre_time;//更新时间
	private String plan_group_flag;//是否小组计划
	private String plan_attendance;//计划参与度
	private String plan_contribution;//计划贡献度
	private String plan_note;//备注
	/**
	 * 表头查询框
	 */
	private String stuId;
	private String stuName;
	private String groupName;
	private String taskId;
	private String majorId;
	private String facultyId;
	/**
	 * 查询个人计划表头
	 * @return
	 */
	public String queryPlanHead(){
		try {
			List list = baseDao.queryPlanHeadC02(user_id, user_role_id, stuId, stuName, groupName, taskId, majorId, facultyId);
			this.rows = (JSONArray) JSONArray.toJSON(list);
			return "queryPlanHeadC02";
		} catch (Exception e) {
			System.out.println(this.message+e.getMessage());
			return "queryPlanHeadC02";
		}
	}
	/**
	 * 查询个人计划表体
	 * @return
	 */
	public String queryPlanBody(){
		try {
			List list = baseDao.queryPlanBodyC02(stu_id);
			this.rows = (JSONArray) JSONArray.toJSON(list);
			return "queryPlanBodyC02";
		} catch (Exception e) {
			System.out.println(this.message+e.getMessage());
			return "queryPlanBodyC02";
		}
	}
	/**
	 * 增加
	 * @return
	 */
	public String addPlan(){
		try {
			this.plan_id = IDFactory.getID();
			int[] array = IDFactory.getSqlTime();
			this.plan_cre_time =new Date(array[0], array[1], array[2]);
			this.plan_group_flag = "N";
			int i = baseDao.addPlan(plan_id, plan_stu_id.substring(0, 10), plan_week, plan_expect, plan_done, plan_cre_time,
					plan_group_flag, plan_attendance, plan_contribution, plan_note);
			if(i == 1){
				baseDao.setReturnInfo(message, "Y", "增加个人计划成功!");
			}else {
				baseDao.setReturnInfo(message, "N", "增加个人计划失败!请稍后再试!");
			}
			return "addPlanC02";
		} catch (Exception e) {
			System.out.println("新增个人计划异常:"+e.getMessage());
			baseDao.setReturnInfo(message, "N", "新增个人计划异常!");
			return "addPlanC02";
		}
	}
	/**
	 * Check计划周 不重复
	 */
	public String checkAddPlan(){
		int i = 0;
		if(plan_week == null || plan_week.equals("")){
			baseDao.setReturnInfo(message, "N", "计划周不能为空!");
			return "addPlanC02";
		}
		if (stu_id == null) {
			baseDao.setReturnInfo(message, "N", "此次登录会话失效,请重新登录!");
			return "addPlanC02";
		}
		i = baseDao.checkPlanWeek(stu_id, plan_week, Plan.NOT_GROUP_PLAN);
		if(i >= 1){
			baseDao.setReturnInfo(message, "N", "第"+plan_week+"周计划已经添加!");
		}else{
			baseDao.setReturnInfo(message, "Y", "校验通过!");
		}
		return "addPlanC02";
	}
	/**
	 * 修改
	 * @return
	 */
	public String updatePlan(){
		try {
			int[] array = IDFactory.getSqlTime();
			this.plan_cre_time =new Date(array[0], array[1], array[2]);
			this.plan_group_flag = "N";
			int i = baseDao.updatePlan(plan_id, plan_week, plan_expect, plan_done, plan_cre_time,
					plan_attendance, plan_contribution, plan_note);
			System.out.println("修改【"+i+"】条Plan数据");
			if(i == 1){
				baseDao.setReturnInfo(message, "Y", "修改个人计划成功!");
			}else {
				baseDao.setReturnInfo(message, "N", "修改个人计划失败!请稍后再试!");
			}
			return "updatePlanC02";
		} catch (Exception e) {
			System.out.println("修改个人计划异常");
			return "updatePlanC02";
		}
		
	}
	/**
	 * 删除
	 * @return
	 */
	public String removePlan(){
		int i = baseDao.removePlan(plan_id);
		if (i == 1) {
			baseDao.setReturnInfo(message, "Y", "删除成功!");
		} else {
			baseDao.setReturnInfo(message, "N", "删除失败!请稍后再试!");
		}
		return "removePlanC02";
	}
	
	public Map<String, String> getMessage() {
		return message;
	}
	public void setMessage(Map<String, String> message) {
		this.message = message;
	}
	public BaseDao getBaseDao() {
		return baseDao;
	}
	public void setBaseDao(BaseDao baseDao) {
		this.baseDao = baseDao;
	}
	public JSONArray getRows() {
		return rows;
	}
	public void setRows(JSONArray rows) {
		this.rows = rows;
	}
	public String getUser_id() {
		return user_id;
	}
	public void setUser_id(String userId) {
		user_id = userId;
	}
	public String getUser_role_id() {
		return user_role_id;
	}
	public void setUser_role_id(String userRoleId) {
		user_role_id = userRoleId;
	}
	public String getStu_id() {
		return stu_id;
	}
	public void setStu_id(String stuId) {
		stu_id = stuId;
	}
	public String getPlan_id() {
		return plan_id;
	}
	public void setPlan_id(String planId) {
		plan_id = planId;
	}
	public String getPlan_stu_id() {
		return plan_stu_id;
	}
	public void setPlan_stu_id(String planStuId) {
		plan_stu_id = planStuId;
	}
	public String getPlan_week() {
		return plan_week;
	}
	public void setPlan_week(String planWeek) {
		plan_week = planWeek;
	}
	public String getPlan_expect() {
		return plan_expect;
	}
	public void setPlan_expect(String planExpect) {
		plan_expect = planExpect;
	}
	public String getPlan_done() {
		return plan_done;
	}
	public void setPlan_done(String planDone) {
		plan_done = planDone;
	}
	public Date getPlan_cre_time() {
		return plan_cre_time;
	}
	public void setPlan_cre_time(Date planCreTime) {
		plan_cre_time = planCreTime;
	}
	public String getPlan_group_flag() {
		return plan_group_flag;
	}
	public void setPlan_group_flag(String planGroupFlag) {
		plan_group_flag = planGroupFlag;
	}
	public String getPlan_attendance() {
		return plan_attendance;
	}
	public void setPlan_attendance(String planAttendance) {
		plan_attendance = planAttendance;
	}
	public String getPlan_contribution() {
		return plan_contribution;
	}
	public void setPlan_contribution(String planContribution) {
		plan_contribution = planContribution;
	}
	public String getPlan_note() {
		return plan_note;
	}
	public void setPlan_note(String planNote) {
		plan_note = planNote;
	}
	public String getStuId() {
		return stuId;
	}
	public void setStuId(String stuId) {
		this.stuId = stuId;
	}
	public String getStuName() {
		return stuName;
	}
	public void setStuName(String stuName) {
		this.stuName = stuName;
	}
	public String getGroupName() {
		return groupName;
	}
	public void setGroupName(String groupName) {
		this.groupName = groupName;
	}
	public String getTaskId() {
		return taskId;
	}
	public void setTaskId(String taskId) {
		this.taskId = taskId;
	}
	public String getMajorId() {
		return majorId;
	}
	public void setMajorId(String majorId) {
		this.majorId = majorId;
	}
	public String getFacultyId() {
		return facultyId;
	}
	public void setFacultyId(String facultyId) {
		this.facultyId = facultyId;
	}
}
